package com.shop.controller;

import com.alipay.api.AlipayApiException;
import com.shop.common.BeanUtil;
import com.shop.common.result.Result;
import com.shop.common.result.util.ResultModel;
import com.shop.service.pay.PayService;
import com.shop.shopEnum.PayEnum;
import com.shop.vo.PaymentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "支付前端控制器")
@RequestMapping("pay")
public class PayController {

    /**
     * 支付接口
     *
     * @return
     * @throws AlipayApiException
     */
    @PostMapping(value = "payment")
    @ApiOperation(value = "支付接口",notes = "靳旺")
    public ResultModel payment(@RequestBody PaymentVo paymentVo) throws Exception {
        Assert.notNull(paymentVo.getPayType(), "请求类型不能为空！");
        String code = PayEnum.selectImplByType(paymentVo.getPayType());
        Assert.notNull(code, "没有找到请类型对应实现类！");
        PayService payService = BeanUtil.getBeanByBeanName(code, PayService.class);
        return Result.successResultModel(payService.payment(paymentVo));
    }

}
